<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    
    <script>
        let obj = {
            name:'张三',
            age:15,
            code:200
        }
        console.log(obj);
        // 要想将普通对象存储到缓存或发送给后端，需要转化为json字符串
        let objstring = JSON.stringify(obj) //转化为json字符串
        console.log(objstring);
        console.log(typeof objstring);

        // 写入缓存
        sessionStorage.setItem('obj',objstring)
        // 获取数据
        let newobj = sessionStorage.getItem('obj')
        // 将json字符串转化为json对象
        console.log(JSON.parse(newobj));


        // 深拷贝
        // 利用JSON   实现深拷贝
        let a = JSON.parse(JSON.stringify(obj))
        a.name = '888'
        console.log(a);
        
        
        
        
        
    </script>
</body>
</html>